package com.movie.playvideos.fragment;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.movie.playvideos.R;
import com.movie.playvideos.adapter.CustomMoviesAdapter;
import com.movie.playvideos.model.Movie;

/**
 * Show content of PhimBo in MainActivity's FrameLayout
 * @author Thinhdt1
 *
 */
public class MovieThuyNgaFragment extends Fragment implements OnClickListener {

	private TextView mLatestClip;
	private TextView mMostClip;
	private TextView mRecentlyView;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		return inflater.inflate(R.layout.movie_thuynga_fragment, null);
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		Log.d("Thinhdt", "PhimBoFragment");
		setupViews();
	}
	
	/**
	 * setup viesws, register event
	 */
	private void setupViews() {
		mLatestClip = (TextView) getView().findViewById(R.id.latestClip);
		mMostClip = (TextView) getView().findViewById(R.id.mostView);
		mRecentlyView = (TextView) getView().findViewById(R.id.recentlyView);
		
		mLatestClip.setOnClickListener(this);
		mMostClip.setOnClickListener(this);
		mRecentlyView.setOnClickListener(this);
		
		callClipTab(0);
		resetTextColor(R.id.latestClip);
	}

	@Override
	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.latestClip:
			Log.d("Thinhdt", "latest clip");
			callClipTab(0);
			resetTextColor(R.id.latestClip);
			break;

		case R.id.mostView:
			Log.d("Thinhdt", "most clip");
			callClipTab(1);
			resetTextColor(R.id.mostView);
			break;
			
		case R.id.recentlyView:
			Log.d("Thinhdt", "recently clip");
			callClipTab(2);
			resetTextColor(R.id.recentlyView);
			break;
			
		default:
			break;
		}
	}
	
	private void resetTextColor(int id) {
		switch (id) {
		case  R.id.latestClip:
			mLatestClip.setTextColor(getResources().getColor(R.color.blue_color));
			mMostClip.setTextColor(getResources().getColor(R.color.white_bg_color));
			mRecentlyView.setTextColor(getResources().getColor(R.color.white_bg_color));
			break;

		case R.id.mostView:
			mLatestClip.setTextColor(getResources().getColor(R.color.white_bg_color));
			mMostClip.setTextColor(getResources().getColor(R.color.blue_color));
			mRecentlyView.setTextColor(getResources().getColor(R.color.white_bg_color));
			break;
			
		case R.id.recentlyView:
			mLatestClip.setTextColor(getResources().getColor(R.color.white_bg_color));
			mMostClip.setTextColor(getResources().getColor(R.color.white_bg_color));
			mRecentlyView.setTextColor(getResources().getColor(R.color.blue_color));
			break;
			
		default:
			break;
		}
	}
	
	/**
	 * call the clip tab based tab
	 * @param tab
	 */
	private void callClipTab(int tab) {
		Fragment clipTab = new MovieTabFragment();
		
		FragmentTransaction ft = getFragmentManager().beginTransaction();
		ft.replace(R.id.contentVideos, clipTab);
		// can back fragment
//		ft.addToBackStack(null);
		ft.commit();
		
	}
}
